using System;
using L=Science.Physics.GeneralPhysics;

namespace Serway.Chapter15
{
	/// <summary>
	/// Example01: An Oscillating Object
	/// An obtect oscillates with simple harmonic motion along 
	/// the x axis. Its position varies with time according to 
	/// the equation 
	/// x = 4 m \cos(\pi t + \pi / 4)
	/// where t is in seconds and the angles in the 
	/// parentheses are in radians.
	/// (A) Determine the amplitude. frequency, and period of 
	/// the motion.
	/// A = 4,  f = 0.5 Hz,  T = 2 sec.
	/// (B) Calculate the velocity and acceleration of the object 
	/// at any time t.
	/// v = -4 \pi \sin(\pi t + \pi / 4)
	/// a = -4 \pi\pi \cos(\pi t + \pi / 4)
	/// (C) Using the results of part (B), determine the position, 
	/// velocity, and acceleration of the object at t = 1.00 s.
	/// x = -2.83 m
	/// v = 8.89 m/s
	/// a = 27.9 m/s^2
	/// (D) Determine the maximum speed and maximum acceleration 
	/// of the object.
	/// v_max = 12.6 m/s
	/// a_max = 39.5 m/s^2
	/// (E) Find the displacement of the object 
	/// between t = 0 and t = 1.00 s.
	/// \Delta x = -5.66 m 
	/// </summary>
	public class Example01
	{
		public Example01()
		{
		}
		private string result;
		public string Result
		{
			get{return result;}
		}
		public void Compute()
		{
			L.SimpleHarmonicMotion shm = new L.SimpleHarmonicMotion();
			shm.Amplitude = 4.0;
			shm.AngularFrequency = Math.PI;
			shm.PhaseConstant = Math.PI/4.0;

		    //(A)
            result+="(A)"+Convert.ToString(shm.Amplitude)+"\r\n";
			shm.FindFrequencyFromAngularFrequency();
			result+=Convert.ToString(shm.Frequency)+"\r\n";
			shm.FindPeriodFromFrequency();
			result+=Convert.ToString(shm.Period)+"\r\n";
			//(B) 
			//(C)
			L.Time t = new L.Time();
			t.s = 1.0;
			result+="(C)"+Convert.ToString(shm.Position(t))+"\r\n";
			result+=Convert.ToString(shm.Velocity(t))+"\r\n";
			result+=Convert.ToString(shm.Acceleration(t))+"\r\n";
			//(D)
			result+="(D)"+Convert.ToString(shm.VelocityMaximum)+"\r\n";
			result+=Convert.ToString(shm.AccelerationMaximum)+"\r\n";
			//(E)
			L.Time t0 = new L.Time();
			t0.s = 0.0;
			result+="(E)"+Convert.ToString(shm.Position(t)-shm.Position(t0))+"\r\n";
		}	
	}
}
